/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webserver_gui;

/**
 *
 * @author Vuong
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Timer;
import java.awt.event.*;
import java.util.*;
import org.jdom.JDOMException;

/**
 *
 * @author Vuong
 */
public class TimerLoad implements ActionListener{
    Timer t;
    WebServer_GUIView m_view;
    public TimerLoad(WebServer_GUIView view, int iTime) {
        t = new Timer(iTime * 1000, this);
        t.start();
        m_view = view;
    }
    
    /*
    public static void main(String args[]) {
    TimerLoad td = new TimerLoad();
    // create a dummy frame to keep the JVM running
    //  (for demonstation purpose)
    java.awt.Frame dummy = new java.awt.Frame();
    dummy.setVisible(true);
    }*/

    public void ReStart()
    {
        t.restart();
    }            
    
    public void Stop()
    {
        t.stop();
    }
    
    public Timer Get()
    {
        return t;
    }
    
    public void actionPerformed(ActionEvent e) {
       if (e.getSource() == t) 
       {
            try {
                
                System.out.println("--- TimerLoad: actionPerformed :" + Calendar.getInstance().getTime());
                m_view.Load();
                
            } catch (Exception ex) {
                System.out.println("-ERR TimerLoad: actionPerformed :");
                Logger.getLogger(TimerLoad.class.getName()).log(Level.SEVERE, null, ex);
            }
       }
    }
}

